package com.opo5.logisticsmanagement.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.opo5.logisticsmanagement.common.R;
import com.opo5.logisticsmanagement.domain.PlanList;
import com.opo5.logisticsmanagement.service.PlanListService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@Slf4j
@RestController
@RequestMapping("planlist")
public class PlanListController {
    @Autowired(required = false)
    private PlanListService planListService;

    /**
     * 添加计划列表
     * @param planList
     * @return
     */
//    @PostMapping
//    public R add(@RequestBody PlanList planList){
//        log.info("添加成功");
//        planListService.addPlan(planList);
//        return R.success(200);
//    }

    @PostMapping
    public R save(@RequestBody PlanList planList){
        planListService.save(planList);
        return R.success("添加成功");
    }

    /**
     *
     * @param currentPage
     * @param pageSize
     * @return
     */

    @GetMapping("/{currentPage}/{pageSize}")
    public R getAll(@PathVariable int currentPage,@PathVariable int pageSize,PlanList planList){
//        IPage page=new Page(currentPage,pageSize);
//        planListService.selectPage(page);
        IPage<PlanList> page = planListService.selectPage(currentPage, pageSize, planList);
        return R.success(page);
    }

    /**
     *
     * @param currentPage
     * @param pageSize
     * @return
     */
//    @GetMapping("/{currentPage}/{pageSize}")
//    public R getPage(@PathVariable Integer currentPage,@PathVariable Integer pageSize,PlanList planList) {
//        IPage<PlanList>page=planListService.getPage(currentPage,pageSize,planList);
//        return R.success(page);
//    }

    /**
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public R delList(@PathVariable int id){
        planListService.removeById(id);
        return R.success("删除成功");
    }

    /**
     * @param planList
     * @return
     */
    @PutMapping
    public R putList(@RequestBody PlanList planList){
       planListService.updateById(planList);
        return R.success("修改成功");
    }

}
